﻿using System.ServiceModel;
using System.Xml;

namespace TraceView.Shared
{
    [ServiceContract]
    public interface ITraceService
    {
        [OperationContract(IsOneWay = true)]
        void Trace(TraceData data);
    }

    public static class TraceServiceClient
    {
        public static ITraceService Create(string host = "localhost")
        {
            var binding = new NetTcpBinding(SecurityMode.None, false)
                          { ReaderQuotas = XmlDictionaryReaderQuotas.Max, MaxReceivedMessageSize = int.MaxValue };
            string endpoint = string.Format("net.tcp://{0}:9001/TraceView", host ?? "localhost");
            var endpointAddress = new EndpointAddress(endpoint);

            var factory = new ChannelFactory<ITraceService>(binding, endpointAddress);
            ITraceService serviceClient = factory.CreateChannel();
            return serviceClient;
        }
    }
}